package lv.dysnomia.songs.util

import scala.xml.Node
import scala.xml.XML
import scala.xml.factory.XMLLoader
import java.net.URL
import scala.io.Source.fromInputStream

object SongDownloader {

  def main(args: Array[String]): Unit = {
    val content = XML.load("http://www.ante.lv/xwiki/bin/view/NotisIP/WebHome?xpage=xml")
    val node = content\\"renderedcontent"
    val list:Node = XML.loadString(node.text)
    
    var count = 0;
    for (n <- list\"li") {
    	val songUrl = new URL("http://www.ante.lv" + n\"span"\"a"\"@href"  + "?xpage=xml")    	
    	println("songurl = " + songUrl)
    	val songContent = XML.load(songUrl)
    	val songNode = songContent\\"renderedcontent"
    	if (count == 0) {
    		println(songNode.text)
    	count = count + 1
    	}

    }
    
//    val out = new java.io.FileWriter("objects.js")
//    out.write(middle)
//    out.close()
  }
}